package controller;

import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import common.model.Record;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import service.LukeService;
import service.OrderService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

@Path(value = "/", viewPath = "/pages")
public class HomeController extends Controller {

    public void index(){
        redirect("/list?page=1");
    }

    public void list(){
        int page=getInt("page");
        setAttr("page",page);
        setAttr("datas",new OrderService(page).getOneWeekDatas(page));
        render("xuanke.html");
    }

    public void yuyue(){
        String sheying=get("sheying");
        String name=get("name");
        int jieci=getInt("jieci");
        String day=get("day");
        String xingqi=get("xingqi");
        setAttr("erro",new OrderService().yuyue(sheying,name,jieci,day,xingqi));
        renderJson();
    }

    public void quxiaoyuyue(){
        setAttr("erro",new OrderService().quxiaoyuyue(get("id"),get("name")));
        setAttr("data","");
        renderJson();
    }

    public void myrecord(){
        String who=get("who");
        setAttr("name",who);
        setAttr("datas",new OrderService().getMyDatas(who));
        render("my-record.html");
    }

    public void changestate(){
        String id=get("id");
        new LukeService().changeState(id);
        setAttr("erro",0);
        renderJson();
    }
}
